class Trade {
  constructor(id, symbol, type, quantity, price, timestamp) {
    this.id = id;                   // 交易ID
    this.symbol = symbol;           // 股票代码
    this.type = type;               // 交易类型: 'BUY' 或 'SELL'
    this.quantity = quantity;       // 交易数量
    this.price = price;             // 交易价格
    this.timestamp = timestamp;     // 交易时间
    this.status = 'PENDING';        // 交易状态: 'PENDING', 'EXECUTED', 'CANCELLED'
  }

  // 执行交易
  execute() {
    this.status = 'EXECUTED';
    this.timestamp = new Date();
  }

  // 取消交易
  cancel() {
    this.status = 'CANCELLED';
  }

  // 获取交易信息
  getInfo() {
    return {
      id: this.id,
      symbol: this.symbol,
      type: this.type,
      quantity: this.quantity,
      price: this.price,
      timestamp: this.timestamp,
      status: this.status
    };
  }

  // 计算交易总金额
  getTotalAmount() {
    return this.quantity * this.price;
  }
}

module.exports = Trade;